package com.ilvyou.api.controller.common;

import com.ilvyou.api.bean.result.Result;
import com.ilvyou.api.bean.result.Version;
import com.ilvyou.api.controller.BaseController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by GuanYuCai on 2016/9/21 0021.
 */
@Controller
public class AppController extends BaseController {

    @Value("#{configProperties['version.code']}")
    private int versionCode;

    @Value("#{configProperties['version.no']}")
    private String versionNo;

    @Value("#{configProperties['version.desc']}")
    private String versionDesc;

    @Value("#{configProperties['version.url']}")
    private String versionUrl;

    @RequestMapping(value="/app/banners", method= RequestMethod.POST)
    @ResponseBody
    public Result monthBill(@RequestParam String token, String month) throws Exception{
        return success("");
    }

    @RequestMapping("/app/update")
    @ResponseBody
    public Result update(@RequestParam String source, int version) throws Exception{
        if ("Android".equals(source) && version < versionCode){
            Version v = new Version();
            v.desc = versionDesc;
            v.url = versionUrl;
            v.version = versionNo;
            v.force = 0;
            return success(v);
        }

        return fail("没有新版本");
    }
}
